package com.qinggeng.framework.config.thread;

import com.alibaba.fastjson.JSONObject;
import com.qinggeng.common.utils.spring.SpringUtils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 用于获取自定义线程池
 * @author Zheng Jie
 * @date 2019年10月31日18:16:47
 */
public class ThreadPoolExecutorUtil {

    private static ThreadPoolExecutor threadPoolExecutor;

   public static ThreadPoolExecutor getPoll (){
        AsyncTaskProperties properties = SpringUtils.getBean(AsyncTaskProperties.class);
        synchronized (ThreadPoolExecutorUtil.class){
            if (threadPoolExecutor==null){
                threadPoolExecutor=new ThreadPoolExecutor(
                        properties.getCorePoolSize(),
                        properties.getMaxPoolSize(),
                        properties.getKeepAliveSeconds(),
                        TimeUnit.SECONDS,
                        new ArrayBlockingQueue<>(properties.getQueueCapacity()),
                        new TheadFactoryName()
                );
            }
        }
        return threadPoolExecutor;
    }
}
